#include "no_xiang_tu0.h"
#include "no_xiang_tu_ban.h"
#include "AdjacencyList.h"
struct node{
    int wei;
    int index;
};
int main() {
    int numVertices ;  // ??????
    int src,dest,weight;
    int m;
    cin>>numVertices>>m;
    WeightedGraph_quan graph(numVertices);
    for(int i=0;i<m;i++){
        cin>>src>>dest>>weight;
        graph.addEdge(src-1,dest-1,weight);
    }
    vector<vector<int>> Graph_get = graph.Graph_get();
    vector<node> a;
    for(int i=0;i<numVertices;i++){
        int max1=0;
        for(int j=0;j<numVertices;j++){
            max1 = max(Graph_get[i][j],max1);
        }
        node n{};
        n.index=i+1;
        n.wei = max1;
        a.push_back(n);
    }
    node min_node{};
    min_node.wei=999;
    for(int i=0;i<numVertices;i++){
        if(a[i].wei<min_node.wei){
            min_node.wei=a[i].wei;
            min_node.index=a[i].index;
        }
    }
    cout<<min_node.index<<" "<<min_node.wei;
////    graph.addEdge(0, 1, 2);
////    graph.addEdge(1, 2, 3);
////    graph.addEdge(2, 3, 4);
////    graph.addEdge(3, 4, 5);
////    graph.addEdge(4, 0, 6);
//    cout << "" << endl;
//    graph.printGraph();
////    vector<vector<Edge>> inverseAdjacencyList = graph.convertToInverseAdjacencyList();
////    cout << "Inverse Adjacency List:" << endl;
////    for (int i = 0; i < numVertices; ++i) {
////        cout << "Vertex " << i << " <-- ";
////        for (const Edge& edge : inverseAdjacencyList[i]) {
////            cout << "(" << edge.dest << ", " << edge.weight << ") ";
////        }
////        cout << endl;
////    }.
//    vector<int> dist;
//    graph.Dijkstra(0,dist);
//    cout << "Shortest distances from node " << 0 << ":" << endl;
//    for (int i = 0; i < numVertices; ++i) {
//        cout << "Node " << i << ": " << dist[i] << endl;
//    }
    return 0;
}